import axios from 'axios'
// import { Toast } from 'vant'
import { getToken } from './storage'
import { Toast } from 'vant'

// import router from '@/router'
const request = axios.create({
  baseURL: 'http://liufusong.top:8080'
  // timeout: 5000
})

// 添加请求拦截器
request.interceptors.request.use(function (config) {
  const token = getToken()
  if (token) {
    config.headers.authorization = token
  }
  Toast.loading({
    message: '加载中...',
    duration: 3000
  })
  console.log(config)
  return config
}, function (error) {
  return Promise.reject(error)
})

// 添加响应拦截器
request.interceptors.response.use(function (response) {
  return response.data
}, function (error) {
  // 对响应错误做点什么

  return Promise.reject(error)
})

export default request
